package everydayGrade.t5;

import java.util.Arrays;
import java.util.Stack;

/**
 * @Author: Siantar
 * @Date: 2023-12-12-18:23
 * @Description: 1.0
 */
public class T0503 {
    public int[] nextGreaterElements(int[] nums) {
        Stack<Integer> stack = new Stack<>();
        int n = nums.length;
        int[] res = new int[n];
        Arrays.fill(res,-1);
        for (int i = 0; i < 2 * n; i++) {
            while (!stack.isEmpty() && nums[stack.peek()] < nums[i % n]) {
                res[stack.pop()] = nums[i % n];
            }
            stack.push(i % n);
        }
        return res;
    }
}
